module AdminHelper
  def mark_field_as sym
    case sym
      when :required
        "<span class=\"required\">#{l(:common, :required)}</span>"        
      when :optional
        "<span class=\"optional\">#{l(:common, :optional)}</span>" 
      else
        ''
    end
  end
  
  # for use for artists and artworks
  def check_requirements type, object=nil
    @checked_requirements = true
    @requirements = {}
    if type == :artwork
      object ||= @artwork
      @requirements[:description] = ArtworkDescription.find_all_by_artwork_id(object.id).size
      @requirements[:media] = Picture.find_all_by_artwork_id(object.id).size
    elsif type == :artist
      object ||= @artist
      @requirements[:description] = ArtistDescription.find_all_by_artist_id(object.id).size
      @requirements[:media] = Picture.find_all_by_artist_id(object.id).size
    end
  end
  
  def meets_requirements?
    # FIXME: figure out instance variables in helpers/modules so this will work
    #check_requirements unless checked_requirements
    ret = true
    @requirements.each_value do |val|
      ret &&= val.to_i > 0
    end
    ret
  end
end
